package com.mankind.ssm.service;

import com.mankind.ssm.mapper.PermissionMapper;
import com.mankind.ssm.mapper.RolePermissionMapper;
import com.mankind.ssm.pojo.Permission;
import com.mankind.ssm.pojo.Role;
import com.mankind.ssm.pojo.RolePermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Mankind on 2017/7/21.
 */
@Service("rolePermissionSerivce")
public class RolePermissionServiceImpl implements RolePermissionService{
    @Autowired
    private RolePermissionMapper rolePermissionMapper;
    @Autowired
    private PermissionMapper permissionMapper;
    public void deleteByRoleId(Integer roleId) {
        rolePermissionMapper.deleteByRoleId(roleId);
    }

    public void deleteByPermissionId(Integer permissionId) {
        rolePermissionMapper.deleteByPermissionId(permissionId);
    }

    public List<Permission> getPermissionByRoleId(Integer roleId) {
        List<RolePermission> list=rolePermissionMapper.selectPermissionByRoleId(roleId);
        List<Permission> permissionList=new ArrayList<Permission>();
        int size=list.size();
        for(int i=0;i<size;i++){
            System.out.println(list.get(i).getRoleId());
            permissionList.add(permissionMapper.selectByPrimaryKey(list.get(i).getPermissionId()));
        }
        return permissionList;
    }

    public void insert(RolePermission rolePermission) {
        rolePermissionMapper.insert(rolePermission);
    }
}
